#!/usr/bin/perl

use JSON;

my $js = <<EOD;
{"marker":[
{"pref":"北海道","url":"http://www.pref.hokkaido.lg.jp/","addr":"北海道札幌市中央区北3条西6丁目","lat":43.064301,"lng":141.346874},
{"pref":"青森県","url":"http://www.pref.aomori.lg.jp/","addr":"青森県青森市長島一丁目1-1","lat":40.824622,"lng":140.740598},
{"pref":"岩手県","url":"http://www.pref.iwate.jp/","addr":"岩手県盛岡市内丸10番1号","lat":39.7036,"lng":141.152709},
{"pref":"宮城県","url":"http://www.pref.miyagi.jp/","addr":"宮城県仙台市青葉区本町3丁目8番1号","lat":38.268812,"lng":140.872082},
{"pref":"秋田県","url":"http://www.pref.akita.lg.jp/","addr":"秋田県秋田市山王四丁目1-1","lat":39.718611,"lng":140.102401},
{"pref":"山形県","url":"http://www.pref.yamagata.jp/","addr":"山形県山形市松波二丁目8-1","lat":38.240422,"lng":140.363592},
{"pref":"福島県","url":"http://www.pref.fukushima.jp/","addr":"福島県福島市杉妻町2-16","lat":37.750301,"lng":140.467522},
{"pref":"茨城県","url":"http://www.pref.ibaraki.jp/","addr":"茨城県水戸市笠原町978番6","lat":36.341793,"lng":140.446802},
{"pref":"栃木県","url":"http://www.pref.tochigi.jp/","addr":"栃木県宇都宮市塙田1-1-20","lat":36.566672,"lng":139.883093},
{"pref":"群馬県","url":"http://www.pref.gunma.jp/","addr":"群馬県前橋市大手町1-1-1","lat":36.390698,"lng":139.060451},
{"pref":"埼玉県","url":"http://www.pref.saitama.lg.jp/","addr":"埼玉県さいたま市浦和区高砂3-15-1","lat":35.857431,"lng":139.648901},
{"pref":"千葉県","url":"http://www.pref.chiba.jp/","addr":"千葉県千葉市中央区市場町1-1","lat":35.605045,"lng":140.123325},
{"pref":"東京都","url":"http://www.metro.tokyo.jp/","addr":"東京都新宿区西新宿2-8-1","lat":35.689753,"lng":139.691731},
{"pref":"神奈川県","url":"http://www.pref.kanagawa.jp/","addr":"神奈川県横浜市中区日本大通1","lat":35.447495,"lng":139.6424},
{"pref":"新潟県","url":"http://www.pref.niigata.jp/","addr":"新潟県新潟市中央区新光町4番地1","lat":37.902419,"lng":139.023225},
{"pref":"富山県","url":"http://www.pref.toyama.jp/","addr":"富山県富山市新総曲輪1番7号","lat":36.695275,"lng":137.211342},
{"pref":"石川県","url":"http://www.pref.ishikawa.jp/","addr":"石川県金沢市鞍月1丁目1番地","lat":36.59473,"lng":136.625582},
{"pref":"福井県","url":"http://www.pref.fukui.jp/","addr":"福井県福井市大手3-17-1","lat":36.065219,"lng":136.221682},
{"pref":"山梨県","url":"http://www.pref.yamanashi.jp/pref/","addr":"山梨県甲府市丸の内1-6-1","lat":35.664161,"lng":138.568459},
{"pref":"長野県","url":"http://www.pref.nagano.jp/","addr":"長野県長野市大字南長野字幅下692-2","lat":36.651296,"lng":138.181239},
{"pref":"岐阜県","url":"http://www.pref.gifu.lg.jp/","addr":"岐阜県岐阜市薮田南2-1-1","lat":35.391228,"lng":136.722311},
{"pref":"静岡県","url":"http://www.pref.shizuoka.jp/","addr":"静岡県静岡市葵区追手町9番6号","lat":34.976944,"lng":138.383009},
{"pref":"愛知県","url":"http://www.pref.aichi.jp/","addr":"愛知県名古屋市中区三の丸三丁目1番2号","lat":35.180344,"lng":136.906632},
{"pref":"三重県","url":"http://www.pref.mie.jp/","addr":"三重県津市広明町13","lat":34.730272,"lng":136.508598},
{"pref":"滋賀県","url":"http://www.pref.shiga.jp/","addr":"滋賀県大津市京町四丁目1番1号","lat":35.004528,"lng":135.868607},
{"pref":"京都府","url":"http://www.pref.kyoto.jp/","addr":"京都府京都市上京区下立売通新町西入薮ノ内町","lat":35.021393,"lng":135.755439},
{"pref":"大阪府","url":"http://www.pref.osaka.jp/","addr":"大阪府大阪市中央区大手前2丁目","lat":34.686555,"lng":135.519474},
{"pref":"兵庫県","url":"http://web.pref.hyogo.jp/","addr":"兵庫県神戸市中央区下山手通5丁目10番1号","lat":34.691287,"lng":135.183061},
{"pref":"奈良県","url":"http://www.pref.nara.jp/","addr":"奈良県奈良市登大路町30","lat":34.685326,"lng":135.832751},
{"pref":"和歌山県","url":"http://www.pref.wakayama.lg.jp/","addr":"和歌山県和歌山市小松原通1-1","lat":34.226041,"lng":135.167504},
{"pref":"鳥取県","url":"http://www.pref.tottori.lg.jp/","addr":"鳥取県鳥取市東町1丁目220","lat":35.503867,"lng":134.237716},
{"pref":"島根県","url":"http://www.pref.shimane.lg.jp/","addr":"島根県松江市殿町1番地","lat":35.472324,"lng":133.05052},
{"pref":"岡山県","url":"http://www.pref.okayama.jp/","addr":"岡山県岡山市内山下2丁目4番6号","lat":34.661759,"lng":133.934399},
{"pref":"広島県","url":"http://www.pref.hiroshima.lg.jp/","addr":"広島県広島市中区基町10-52","lat":34.396603,"lng":132.459621},
{"pref":"山口県","url":"http://www.pref.yamaguchi.jp/","addr":"山口県山口市滝町1番1号","lat":34.18613,"lng":131.470497},
{"pref":"徳島県","url":"http://www.pref.tokushima.jp/","addr":"徳島県徳島市万代町1丁目1番地","lat":34.065756,"lng":134.559297},
{"pref":"香川県","url":"http://www.pref.kagawa.jp/","addr":"香川県高松市番町4-1-10","lat":34.340045,"lng":134.043369},
{"pref":"愛媛県","url":"http://www.pref.ehime.jp/","addr":"愛媛県松山市一番町4丁目4-2","lat":33.841669,"lng":132.765371},
{"pref":"高知県","url":"http://www.pref.kochi.jp/","addr":"高知県高知市丸ノ内1丁目2番20号","lat":33.5597,"lng":133.531096},
{"pref":"福岡県","url":"http://www.pref.fukuoka.lg.jp/","addr":"福岡県福岡市博多区東公園7番7号","lat":33.606781,"lng":130.418307},
{"pref":"佐賀県","url":"http://www.pref.saga.lg.jp/web/","addr":"佐賀県佐賀市城内1丁目1-59","lat":33.24957,"lng":130.299804},
{"pref":"長崎県","url":"http://www.pref.nagasaki.jp/","addr":"長崎県長崎市江戸町2-13","lat":32.744814,"lng":129.8737},
{"pref":"熊本県","url":"http://www.pref.kumamoto.jp/","addr":"熊本県熊本市水前寺6丁目18番1号","lat":32.789816,"lng":130.74169},
{"pref":"大分県","url":"http://www.pref.oita.jp/","addr":"大分県大分市大手町3丁目1番1号","lat":33.238205,"lng":131.612625},
{"pref":"宮崎県","url":"http://www.pref.miyazaki.lg.jp/","addr":"宮崎県宮崎市橘通東二丁目10番1号","lat":31.911058,"lng":131.423883},
{"pref":"鹿児島県","url":"http://www.pref.kagoshima.jp/","addr":"鹿児島県鹿児島市鴨池新町10番1号","lat":31.560166,"lng":130.557994},
{"pref":"沖縄県","url":"http://www.pref.okinawa.jp/","addr":"沖縄県那覇市泉崎1-2-2","lat":26.212418,"lng":127.680895}
]
}
EOD

my $obj = jsonToObj($js);
use Data::Dumper;
#print Dumper($obj->{marker});

print <<EOD;
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
  <Document>
EOD

for my $pref (@{$obj->{marker}}) {
    printf("    <Placemark>\n      <name>%s</name>\n      <description>%s</description>\n      <Point><coordinates>%s,%s,0</coordinates></Point>\n    </Placemark>\n",
	   $pref->{pref}, $pref->{addr}, $pref->{lng}, $pref->{lat});
}

print <<EOD;
    <Placemark>
      <name>Traveling</name>
      <LineString>
        <coordinates>
EOD

for my $pref (@{$obj->{marker}}) {
    printf("          %s,%s,0\n", $pref->{lng}, $pref->{lat});
}

my $pref = $obj->{marker}->[0];
printf("          %s,%s,0\n", $pref->{lng}, $pref->{lat});

print <<EOD;
        </coordinates>
      </LineString>
    </Placemark>
EOD

print <<EOD;
  </Document>
</kml>
EOD
